package com.xuedian.xuanxuan.web.service.impl;


import com.xuedian.xuanxuan.core.generic.GenericDao;
import com.xuedian.xuanxuan.core.generic.GenericServiceImpl;
import com.xuedian.xuanxuan.web.dao.MUserMapper;
import com.xuedian.xuanxuan.web.model.User;
import com.xuedian.xuanxuan.web.service.MUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class MUserServiceImpl extends GenericServiceImpl<User, Long> implements MUserService {

    @Resource
    private MUserMapper mUserMapper;

    @Override
    public int insert(User model) {
        try {
            mUserMapper.insertSelective(model);
        }catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int update(User model) {
        return mUserMapper.updateByPrimaryKeySelective(model);
    }

    @Override
    public int delete(Long id) {
        return mUserMapper.deleteByPrimaryKey(id);
    }

    @Override
    public User selectById(Long id) {
        return mUserMapper.selectByPrimaryKey(id);
    }

    @Override
    public GenericDao<User, Long> getDao() {
        return mUserMapper;
    }


    @Override
    public User selectByOpenId(String openId, Integer type) {
        try {
            List<User> list = mUserMapper.selectByOpenId(openId,type);
            if (list!=null&&list.size()>0){
                return list.get(0);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
//        List<User> list = mUserMapper.selectByOpenId(openId,type);
//        if (list!=null&&list.size()>0){
//            return list.get(0);
//        }
        return null;
    }

    @Override
    public User selectInfo(Long userId) {
        final List<User> list = mUserMapper.selectInfo(userId);
        if (list!=null&&list.size()>0){
            return list.get(0);
        }
        return null;
    }
}
